package cn.wbnyua.resume.core.security;

import cn.wbnyua.resume.util.JsonResponse;
import com.alibaba.fastjson2.JSON;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 作者：wbnyua.
 * 创建时间: 2023/2/13 11:18.
 */


@Component
public class MyLoginSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request,
                                        HttpServletResponse response,
                                        Authentication authentication)
            throws ServletException, IOException {

        response.setContentType("application/json;charset=UTF-8");

        JsonResponse<Object> jsonResponse = new JsonResponse<>("200", "登录成功");

        String result = JSON.toJSONString(jsonResponse);

        response.getWriter().write(result);
    }
}
